<!--
 * @Descripttion: 异步选择器
 * @version: 1.0
 * @Author: sakuya
 * @Date: 2021年8月3日15:53:37
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @LastEditTime: 2023-09-28 10:14:54
-->

<template>
  <sk-select
    :apiObj="url"
    :valueEqKey="valueEqKey"
    @valueChange="valueChange"
    :editsource="editsource"
    @select="select"
    :disabled="disabled"
    :filterparams="filterparams"
    :params="params"
    :dicparams="dicparams"
    :autoconfigparams="autoconfigparams"
    :placeholder="placeholder"
    :data="data"
    type="width:100%"
  />
</template>

<script>
import skSelect from "./../skSelect";
import config from "@/config/autocomplete";
export default {
  emits: ["dicSelect", "select"],
  props: {
    code: { type: String, default: () => "" },
    valueEqKey: { type: Boolean, default: false },
    placeholder: { type: String, default: () => "" },
    editsource: { type: String, default: () => "dic" },
    filterparams: null,
    params: null,
    disabled: { type: Boolean, default: false },
    data: { type: Array, default: () => null },
  },
  components: { skSelect },

  data() {
    return {
      url:
        this.editsource != "dic"
          ? config[this.code].url
          : this.$API.system.dic.getDicData,
      dicparams: { code: this.code },
      autoconfigparams: config[this.code]?.params ?? null,
    };
  },

  methods: {
    select(data) {
      this.$emit("select", data);
    },
    valueChange(data) {
      this.$emit("dicSelect", data);
    },
  },
};
</script>
